<?php
require_once 'src/car/car.class.php';
require_once 'src/car/dao.class.php';
require_once 'config.php';
$id = $_REQUEST['carId'];
if (isset($_POST['pic0'])) {
	$current = $_POST['current'];  
	$pic0 = $_POST['pic0'];
	$pic1 = $_POST['pic1'];
	$pic2 = $_POST['pic2'];
	$pic3 = $_POST['pic3'];
	$pic4 = $_POST['pic4'];
} else {
	$car = CarDao::find($id);
	$current = $car->photo;
	$pic0 = $car->photo;
	$pic1 = $car->pic1;
	$pic2 = $car->pic2;
	$pic3 = $car->pic3;
	$pic4 = $car->pic4;
}
$objEF = new ST_PHPForm();
$objEF->UseLocator();
$objEF->SetIndent("			");
?>
<html >
<head>
<link type="text/css" rel="Stylesheet" href="css/simplicity/theme.css" media="screen"/>
<script type="text/javascript">
var pic0 = "img/cars/<?php echo $pic0?>";
var pic1 = "img/cars/<?php echo $pic1?>";
var pic2 = "img/cars/<?php echo $pic2?>";
var pic3 = "img/cars/<?php echo $pic3?>";
var pic4 = "img/cars/<?php echo $pic4?>";
function ChangeClassName(strMenuId, strClassName){
	var e;
	e = document.getElementById(strMenuId);
	e.className = strClassName;
}
</script>
</head>
<table>
  <tr>
  	<td>
  	<table>
  	<tr>
    <td>
    	<?php
    	if ($pic0 != "" && !is_null($pic0)){ 
    	?>
    	<a href="#" onclick="document.currentPic.src=pic0">
    	<img src="img/cars/_thb_<?php echo $pic0;?>" width="100px" height="100px"/></a>
    </td>
    <td>
    	<?php 
    	} 
    	if ($pic1 != "" && !is_null($pic1)){ 
    	?>
    	<a href="#" onclick="document.currentPic.src=pic1">
    	<img src="img/cars/_thb_<?php echo $pic1;?>" width="100px" height="100px" /></a>
    </td>
    <td>
    	<?php 
    	} 
    	if ($pic2 != "" && !is_null($pic2)){ 
    	?>
    	<a href="#" onclick="document.currentPic.src=pic2">
    	<img src="img/cars/_thb_<?php echo $pic2;?>" width="100px" height="100px" /></a>
    </td>
    <td>
    	<?php 
    	} 
    	if ($pic3 != "" && !is_null($pic3)){ 
    	?>
    	<a href="#" onclick="document.currentPic.src=pic3">
    	<img src="img/cars/_thb_<?php echo $pic3;?>" width="100px" height="100px" /></a>	
    </td>
    <td>
    	<?php 
    	} 
    	if ($pic4 != "" && !is_null($pic4)){ 
    	?>
    	<a href="#" onclick="document.currentPic.src=pic4">
    	<img src="img/cars/_thb_<?php echo $pic4;?>" width="100px" height="100px" /></a>
    	<?php 
    	} 
    	?>
    </td>
  	</tr>
  	</table>
  	</td>
  	<td rowspan="2" valign="top">
	<div style="padding-left: 10px;">
  	<table class="STtable">
<?php 
if ($objEF->IsPost()) {
	$objEF->ChEmptiness("email", "Email is empty.");
	$objEF->ChEmailAddr("email", "Invalid Email address");
	if ($objEF->IsValid()) {
		$objMail = $GLOBALS['objMAIL'];
		$topic = $objEF->arrPostData['subject'];
		$topic .= " sent by: ".$objEF->arrPostData['firstname'] . " " . $objEF->arrPostData['lastname'];
		$text = $objEF->arrPostData['message'];
		$text .= "\n\n sent by: ".$objEF->arrPostData['firstname'] . " " . $objEF->arrPostData['lastname'];
		$text .= "\n email :".$objEF->arrPostData['email'];
		$text .= "\n phone number :".$objEF->arrPostData['phone'];
		$text .= "\n mobile number :".$objEF->arrPostData['cell'];
		$text .= "\n car ID :".$id;
		$text .= "\n car URL :".$host.$www."/index_public.php?entity=car&action=details&cid=$id";
		
		$headers['From']    = $objEF->arrPostData['email'];
		$headers['To']    = $recipients;
		$headers['Subject'] = $topic;

		$send = $objMail->send($recipients, $headers, $text);
		if (PEAR::isError($send)) {// print($send->getMessage());
			$objEF->SetError("submit", "Error accour! not send.");
		}else{
			$objEF->SetInfor("submit", "Form sent successfully!");
		} 
		
	}
}
echo $objEF->Open("enquityform");
echo $objEF->HiddenField("carId", $id);

echo "<tr><td><br/><br/><br/>Enquiry Form<br/><br/><br/>";
echo "</td></tr><tr><td>";
echo $objEF->ErrMsgs("STerrmsgs2");
echo $objEF->InfMsgs("STinfmsgs2");
echo "</td></tr><tr><td>";
echo $objEF->Label("firstname" , "First Name:");	
echo "</td></tr><tr><td>";
echo $objEF->TextBox("firstname" , "", "");
echo "</td></tr><tr><td>";
echo $objEF->Label("lastname" , "Last Name:");	
echo "</td></tr><tr><td>";
echo $objEF->TextBox("lastname" , "", "");
echo "</td></tr><tr><td>";
echo $objEF->Label("email" , "Email:");	
echo "</td></tr><tr><td>";
echo $objEF->TextBox("email" , "", "");
echo "</td></tr><tr><td>";
echo $objEF->Label("phone" , "Phone No:");	
echo "</td></tr><tr><td>";
echo $objEF->TextBox("phone" , "", "");
echo "</td></tr><tr><td>";
echo $objEF->Label("cell" , "Mobile No:");	
echo "</td></tr><tr><td>";
echo $objEF->TextBox("cell" , "", "");
echo "</td></tr><tr><td>";
echo $objEF->Label("subject" , "Subject:");	
echo "</td></tr><tr><td>";
echo $objEF->TextBox("subject" , "", "");
echo "</td></tr><tr><td>";
echo $objEF->Label("message" , "Comments:");	
echo "</td></tr><tr><td>";
echo $objEF->TextArea("message" , "", "",array());
echo "</td></tr><tr><td>";
echo $objEF->SubmitButton("submit" , " Send ");
echo $objEF->ResetButton("reset" , " Reset ");
echo "</td></tr><tr><td>";
//echo $objEF->TextArea("message" , "Message:", "",array(), 4,3, 0, true);
//echo $objEF->SubmitButton2("submit", " Send ");
//echo $objEF->Reset("reset", " Reset ",array(),false);
echo $objEF->Close();
  		?>
  	</tr>
  	</table>
	</div>
  	</td>
  </tr>

  <tr>
    <td>
    	<img id="currentPic" name="currentPic" alt="picture" src="img/cars/<?php echo $current;?>" width="538px" height="430px"/>
    </td>
  </tr>		
</table>
</html>